package ee.az.tetris;

import ee.az.tetris.event.DownEvent;
import ee.az.tetris.event.FallStartEvent;
import ee.az.tetris.event.LeftEvent;
import ee.az.tetris.event.RightEvent;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;

/**
 * @author Artur Zinatullin (artur.zinatullin@gmail.com) 2010
 */
public class KeyListener extends KeyAdapter {
	private Dispatcher dispatcher;
	
	public KeyListener(Dispatcher dispatcher) {
		this.dispatcher = dispatcher;
	}
	
	@Override
	public void keyPressed(KeyEvent e) {
		int keyCode = e.getKeyCode();
		switch(keyCode) {
			case 32:
				dispatcher.dispatch(new FallStartEvent());
				e.consume();
				break;
			case 37:
				dispatcher.dispatch(new LeftEvent());
				e.consume();
				break;
			case 38: break;
			case 39:
				dispatcher.dispatch(new RightEvent());
				e.consume();
				break;
			case 40:
				dispatcher.dispatch(new DownEvent());
				e.consume();
				break;
		}
	}
}